Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macros: charecterization tests for ? operator fail #7069

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joshka
Copy link
Contributor

@joshka joshka commented Jan 6, 2025

When a ? operator is used in a tokio entry point function (wrapped in
#[tokio::main]), which has a Option or Result return type, but where
the function does not actually return that type correctly, currently the
compiler returns two errors instead of just one. The first of which is
incorrect and only exists due to the macro expanding to an async block.

cannot use the `?` operator in an async block that returns `()`

This commit is a characterization test for this behavior to help show
when it's fixed (or even changed for better / worse)

Motivation

Annoyed by incorrect error message. "cannot use the ? operator in an async block that returns ()". More specifically, when editing code in ways that break the code (by changing return values, or changing the order of things, seeing error messages that aren't actually relevant to fixes can be annoying, particularly in situations where these errors are reported inline to the code. There's a small amount of time where the brain leaves the problem at hand and moves into solve the bug mode, which is unnecessary (and hence worth addressing)

More details at #6930 (comment)

Solution

This PR is about just identifying and capturing the problem. It can be merged as-is, or can be left open while considering the options to fix this.

When a `?` operator is used in a tokio entry point function (wrapped in
`#[tokio::main]`), which has a Option or Result return type, but where
the function does not actually return that type correctly, currently the
compiler returns two errors instead of just one. The first of which is
incorrect and only exists due to the macro expanding to an async block.

```
cannot use the `?` operator in an async block that returns `()`
```

This commit is a characterization test for this behavior to help show
when it's fixed (or even changed for better / worse)
@Darksonn
Copy link
Contributor

Darksonn commented Jan 6, 2025

cc @Veykril

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-macros Area: The tokio-macros crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants